package main

import (
	"flag"
	"fmt"
	"go.uber.org/zap"
	"laxkits/lib/laxmysql"
	"laxkits/lib/laxoffice"
	"laxkits/lib/laxutils"
)

func main() {
	var execType string
	flag.StringVar(&execType, "t", "Unknown", "<modify> <query> <delete>")
	flag.Parse()
	fmt.Println("type:", execType)
	if err := laxutils.RoInit(); err != nil {
		return
	}
	defer laxutils.RoUninit()
	go func() {
		if execType == "modify" {
			laxmysql.GetLaxMySQLMgr().Foreach(TryModify, laxutils.ROGlobalConfigNode.UsRoutine)
			zap.S().Info("修改完成")
		} else if execType == "query" {
			if cw, err := laxoffice.NewLaxCSVWriter(laxutils.CurTime2FileName("csv"), true); err == nil {
				cw.Write([]string{"服id", "角色id", "名字", "openid", "道具id", "道具uid", "道具数量"})
				laxmysql.GetLaxMySQLMgr().Foreach(func(conn *laxmysql.LaxMySQLConn) {
					TryQuery(conn, cw)
				}, laxutils.ROGlobalConfigNode.UsRoutine)
				cw.WaitFinish()
			} else {
				zap.S().Errorf("打开csv出错:%s", err)
			}
			zap.S().Info("查询完成")
		} else if execType == "delete" {
			laxmysql.GetLaxMySQLMgr().Foreach(TryDelete, laxutils.ROGlobalConfigNode.UsRoutine)
			zap.S().Info("删除完成")
		} else {
			zap.S().Errorf("参数[%s]非法,合法的有<query> <modify> <delete>", execType)
		}
	}()
	laxutils.CloseGracefully(nil)
}
